<?php
/**
 * Created by PhpStorm.
 * User: Hanson
 * Date: 2016/9/25
 * Time: 23:08
 */

namespace App\Repository;


use App\Model\Permission;

class PermissionRepository
{
    protected $permission;

    public function __construct(Permission $permission)
    {
        $this->permission = $permission;
    }

    /**
     * 获取所有权限
     *
     * @return \Illuminate\Database\Eloquent\Collection|static[]
     */
    public function all()
    {
        return Permission::all();
    }

    /**
     * 增加权限
     *
     * @param $name string 权限名
     * @param null $displayName string 权限
     * @param null $description string 权限描述
     * @return bool|\Illuminate\Database\Eloquent\Model
     */
    public function add($name, $displayName = null, $description = null)
    {
        if(!$name) return false;

        return Permission::updateOrCreate(['name' => $name], ['display_name' => $displayName, 'description' => $description]);
    }

    public function delete($id)
    {
        return Permission::destroy($id);
    }
}